/**
 *  Copyright (C) 2006 zhangbo (freeeob@gmail.com)
 *
 *  This product is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 * 
 *  This product is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 *  author:zhangbo
 *  Email:jsjava@gmail.com
 */

/**
 * Return the object value by resolving the expression
 * @param expr a expression string
 */
function $obj(expr){
	if(expr==undefined||expr==null||expr==""){
		return null;
	}
	var parts=expr.split(".");
	var obj;
	for(var i=0;i<parts.length;i++){
		var part=parts[i];
		if(!obj){
			var pos1=part.indexOf("[");
			if(pos1!=-1){				
				var prop=part.substring(0,pos1);
				var key=part.substring(pos1+1,part.length-1);
				obj=eval(prop+".get("+key+")");
			}else{
				obj=eval(part);
			}
		}else{
			var pos1=part.indexOf("[");
			if(pos1!=-1){				
				var prop=part.substring(0,pos1);
				var key=part.substring(pos1+1,part.length-1);
				obj=eval("obj.get"+prop.capitalize()+"().get("+key+")");
			}else{
				obj=eval("obj.get"+part.capitalize()+"()");
			}
		}
	}
	return obj;
}

/**
 * Return the dom value by resolving the expression
 * @param expr a expression string
 */
function $dom(expr){
	if(expr==undefined||expr==null||expr==""){
		return null;
	}
	var parts=expr.split(".");
	var obj=document;
	for(var i=0;i<parts.length;i++){
		var part=parts[i];
		var pos1=part.indexOf("[");
		if(pos1!=-1){				
			var prop=part.substring(0,pos1);
			var key=part.substring(pos1+1,part.length-1);
			var elem=obj.getElementById(prop);
			obj=eval("elem.getAttribute("+key+")");
		}else{
			obj=obj.getElementById(part);
			var tagName=obj.tagName.toUpperCase();
			if(tagName=="IFRAME"||tagName=="FRAME"){
				obj=obj.contentWindow;
			}
		}
	}
	return obj;
}